package hvzt.minimap.activities;

import hvzt.minimap.R;
import hvzt.minimap.location.LocationService;

import android.app.Activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

/**
 * InitActivitity responsible for starting up game and based on if user previously
 * registered game starts differently. 
 * @author JosephM
 */
public class InitActivity extends Activity{
	
	private Button play;
	private Button quit;
	private SharedPreferences prefs;
	
	// override frome extending activity, sets xml layouts and UI
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.init);
		setUpUI();
	}
	
	// private method to help setup UI
	private void setUpUI() {
		play = (Button) findViewById(R.id.play_button);	
		quit = (Button) findViewById(R.id.quit_button);
		prefs = getSharedPreferences("hvzt", MODE_PRIVATE);
        play.setOnClickListener(init);
        quit.setOnClickListener(init);
	}

	// listener for play game and quit game buttons
	private OnClickListener init = new OnClickListener() {
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			// if play button pressed
			case R.id.play_button:
				// if user previously registered
				boolean registered = prefs.getBoolean("registered", false);
//				registered = false; // to go to MapActivity or Registration Acitivity debugger
				Intent intent;
				if (registered) {
					intent = new Intent(InitActivity.this, ZMapActivity.class);
				} else {
					intent = new Intent(InitActivity.this, RegistrationActivity.class);
				}	
				startActivity(intent);
				break;
			case R.id.quit_button:
				// stop location service if user wants to quit game
				stopService(new Intent(InitActivity.this, LocationService.class));
				finish();
				break;
			default:
			}
		}
	};
}
